//
//  BGBasicMessicContentView.m
//  bigMall
//
//  Created by LTOVE on 16/7/21.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGBasicMessicContentView.h"
#import "BGMessageContentModel.h"
#import "MJExtension.h"

#import "BGMessageNameAndValueModel.h"
#import "BGMessageContentFrameModel.h"

@interface BGBasicMessicContentView (){
    /**
     *  标题
     */
    UILabel *_titleLabel;
    UIView *_contentView;
    UILabel *_blueLabel;
    UILabel *_lineLabel;
}


@end

@implementation BGBasicMessicContentView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.width = screenW;
        self.backgroundColor = GWColor(238, 239, 240, 1);
        //        [self setAllSubviews];
    }
    
    
    return self;
}


- (void)setFModel:(BGMessageContentFrameModel *)FModel
{
    _FModel = FModel;
    //    设置View视图的高度
    self.height = FModel.cellHeigh;
    //    创建数据模型
    BGMessageContentModel *model = FModel.dataModel;
    
    //    取出数据模型title属性以及内容数组
    
//    NSArray *dataArray = model.dataArray;
//    //    创建内容控件
//    [self setAllSubviews:dataArray];
//    //    设置标题
//    _titleLabel.text = model.title;
    
}

/**
 *  创建所有子空件
 */
- (void)setAllSubviews:(NSArray *)itemsArray
{
    
    
    //    设置contentView
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height - cellMargen)];
    contentView.backgroundColor = [UIColor whiteColor];
    _contentView = contentView;
    //设置蓝色标签
    UILabel *blueLabel = [[UILabel alloc]init];
    _blueLabel = blueLabel;
    blueLabel.backgroundColor = GWColor(41, 167, 253, 1);
    //设置标题
    UILabel *titleLabel = [[UILabel alloc]init];
    _titleLabel = titleLabel;
    //设置分割线
    UILabel *lineLabel = [[UILabel alloc]init];
    _lineLabel = lineLabel;
    //循环添加内容
    [self setUpContentWith:itemsArray];
}

- (void)setUpContentWith:(NSArray *)dataArray
{
    CGFloat width = (self.width -40)/2.0;
    CGFloat heigh = 45;
    
    int colCount = 2;
    CGFloat maginx = (self.width - colCount * width)/(colCount + 1);
    CGFloat magrnY = 10;
    
    
    for (int i = 0; i < dataArray.count; i++) {
        
        //循环取出数组里的模型
        BGMessageNameAndValueModel * model = dataArray[i];
        NSString *title = [NSString stringWithFormat:@"%@:",model.title];
        NSString *Value = model.value;
        NSString *str = [title stringByAppendingString:Value];
        
        NSMutableParagraphStyle *paragraph=[[NSMutableParagraphStyle alloc]init];
        paragraph.alignment=NSTextAlignmentCenter;//
        
        NSDictionary * att = @{NSFontAttributeName:[UIFont fontWithName:@"AmericanTypewriter" size:30],//文本的颜色 字体 大小
                               NSForegroundColorAttributeName:BGtextNomeColor,//文字颜色
                               NSParagraphStyleAttributeName:paragraph,//段落格式
                               };
        NSMutableAttributedString *attstring = [[NSMutableAttributedString alloc]initWithString:str attributes:att];
        
        [attstring addAttribute:NSForegroundColorAttributeName value:BGtextGraykColor range:NSMakeRange(0, title.length + 1)];
        
        int row = i/colCount;
        
        int col = i%colCount;
        
        CGFloat x =10+ maginx + col * (width + maginx);
        
        CGFloat Y = magrnY + row * (heigh + magrnY);
        UILabel *label = [[UILabel alloc]init];
        //        label.text = str;
        label.attributedText = attstring;
        
        label.backgroundColor = [UIColor redColor];
        //        label.frame = CGRectMake(x, Y, width, heigh);
        label.point = CGPointMake(x, Y);
        [self addSubview:label];
    }
}



@end
